package com.suyuan.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.suyuan.dao.CompanyInfoMapper;
import com.suyuan.dao.VaccineInforMapper;
import com.suyuan.entity.CompanyInfo;
import com.suyuan.entity.CompanyInfoExample;
import com.suyuan.entity.VaccineInfor;
import com.suyuan.entity.VaccineInforExample;
import com.suyuan.service.CompanyInfoService;
import com.suyuan.service.VaccineInfoService;
import com.suyuan.web.Page;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service(value = "vaccineInfoService")
public class VaccineInfoServiceImpl implements VaccineInfoService {
    @Resource
    private CompanyInfoMapper companyInfoMapper;

    @Resource
    private VaccineInforMapper vaccineInforMapper;

    public int save(VaccineInfor vaccineInfor){
        vaccineInfor.setNuminstore(0);
        return vaccineInforMapper.insert(vaccineInfor);
    }

    public int delete(Integer vaccineid) {
        return vaccineInforMapper.deleteByPrimaryKey(vaccineid);
    }

    /**
     *
     * @param vaccinename 疫苗名称
     * @param vaccinetype 疫苗类型
     * @param manufactoryid 生产企业id
     * @param page 分页信息
     * @return
     */
    public PageInfo inquiry(String vaccinename, String vaccinetype,String manufactoryid, Page page) {
        VaccineInforExample vaccineInforExample=new VaccineInforExample();
        VaccineInforExample.Criteria criteria=vaccineInforExample.createCriteria();
        if(vaccinename!=null){
            criteria.andVaccinenameLike("%"+vaccinename+"%");
        }
        if(vaccinetype!=null){
            criteria.andVaccinetypeEqualTo(vaccinetype);
        }
        if(manufactoryid!=null){
            criteria.andManufactoryidEqualTo(manufactoryid);
        }
        PageHelper.startPage(page.getPageNumber(),page.getPageSize());
        List<VaccineInfor> vaccineInfor=vaccineInforMapper.selectByExample(vaccineInforExample);
        PageInfo info = new PageInfo(vaccineInfor);
        return info;
    }

    public VaccineInfor findByVaccineId(Integer vaccineid){
        VaccineInforExample vaccineInforExample=new VaccineInforExample();
        VaccineInforExample.Criteria criteria=vaccineInforExample.createCriteria();
        if(vaccineid!=null){
            criteria.andVaccineidEqualTo(vaccineid);
            return vaccineInforMapper.selectByPrimaryKey(vaccineid);
        }
        return null;
    }

    public int update(VaccineInfor vaccineInfo){
        VaccineInfor vaccineInfor= vaccineInforMapper.selectByPrimaryKey(vaccineInfo.getVaccineid());
        vaccineInfor.setNuminstore(vaccineInfo.getNuminstore());
        int code=vaccineInforMapper.updateByPrimaryKeySelective(vaccineInfor);
        return code;
    }

    public List<VaccineInfor> findAll(){
        VaccineInforExample vaccineInforExample=new VaccineInforExample();
        VaccineInforExample.Criteria criteria=vaccineInforExample.createCriteria();
        List<VaccineInfor> vaccineInfor=vaccineInforMapper.selectByExample(vaccineInforExample);
        return vaccineInfor;
    }
}
